#include "WaveManager.h"
#include "EnemyManager.h"
#include "GameMath.h"
#include "../data/GameInfo.h"
#include "../wave/CircleWave.h"

WaveManager::WaveManager()
{
    GameInfo::Instance().waves.push_back(std::make_shared<CircleWave>());
}

void WaveManager::OnUpdate(double delta)
{
    auto& waves = GameInfo::Instance().waves;
    if (idx >= waves.size()) {
        return;
    }
    waves[idx]->OnUpdate(delta);
    if (!enemyQueue.empty()) {
        GameVector pos = {(double)GameMath::RandomInt(GameInfo::Instance().windowWidth),
                          (double)GameMath::RandomInt(GameInfo::Instance().windowHeight)};
        auto enemy = enemyQueue.front();
        enemy->position = pos;
        if (GameInfo::CheckCollision(enemy.get())) {
            return;
        }
        EnemyManager::Instance().AddEnemy(enemy);
        enemyQueue.pop();
    }
}

void WaveManager::AddBirthQueue(const std::shared_ptr<Character>& enemy)
{
    enemyQueue.push(enemy);
}

